#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <fcntl.h>
#include <unistd.h>

#include <signal.h>

static const char str[] = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ012";

static bool v_exit = false;

static void signal_handler(int sig)
{
//	printf(AJB_DEBUG_INFO, "Called by signal %s (%d)...\n", strsignal(sig), sig);

	switch(sig)
	{
		case SIGINT:
//			printf(AJB_DEBUG_TEST, "SIGINT...\n");
			v_exit = true;
			break;
		case SIGTERM:
//			printf(AJB_DEBUG_TEST, "SIGTERM...\n");
			v_exit = true;
			break;
		case SIGABRT:
//			printf(AJB_DEBUG_TEST, "SIGABRT...\n");
			v_exit = true;
			break;
		case SIGALRM:
//			printf(AJB_DEBUG_TEST, "SIGALRM...\n");
//			printf(AJB_DEBUG_DEAD, "\033[33;1m<BUG> \033[31;1mDeadLock, \033[32;1mAbnormal Exit\033[0m\n");
			v_exit = true;
			exit(0);
			break;
		default:
			break;
	}
}

static void register_signal(void)
{
	signal( SIGINT, signal_handler );
	signal( SIGTERM, signal_handler );
	signal( SIGABRT, signal_handler );
	signal( SIGALRM, signal_handler );
}

int main(int argc, char **argv)
{
	int fd = open("/dev/logman", O_RDWR);
	
	if(0 <= fd)
	{
		register_signal();

		while(false == v_exit)
		{
			if(0 > write(fd, str, sizeof(str) - 1))
			{
				perror("write");
				break;
			}

			usleep(10000);
		}

		printf("exit\n");
	}
	else
	{
		perror("open");
	}

	return 0;
}